<?php

namespace App\Console\Commands\User;

use Illuminate\Console\Command;
use App\Models\User;

class TestUserCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'user:test';

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'user:test
        {username : The username}
        {password : The password}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test if the password right';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        // 获取参数
        $username = $this->argument('username');
        $password = $this->argument('password');

        // 检查用户存在性
        $user = User::where('username', $username)->first();
        if ($user) {
            $flag = password_verify($password, $user->password);
            if ($flag) {
                $this->info('Password right!');
            } else {
                $this->error('Password error!');
            }
        } else {
            $this->error('User not found!');
        }
    }
}
